import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'dart:ui';

import '../../model/config.dart';

class DrawerUserInfo extends StatefulWidget {
  DrawerUserInfo({
    Key key,
    this.csuser
  }):super(key:key);
  Map csuser;
  _DrawerUserInfoState createState() => _DrawerUserInfoState();
}

class _DrawerUserInfoState extends State<DrawerUserInfo> {
  Map csuser;
  @override
  void initState () {
    super.initState();
    csuser = widget.csuser != null ? widget.csuser : {};
  }
  @override

  ImageProvider getCsHeadimg (String path) {
    if (path == '' || path == null) {
      return AssetImage(
        'static/defaultimg.jpg'
      );
    } else {
      return NetworkImage(MyConfig().serverurl + path);
    }
  }

  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Container( // 头像底图
          margin: EdgeInsets.all(0),
          height: ScreenUtil().setWidth(340),
          decoration: BoxDecoration(
            image: DecorationImage(
              image: getCsHeadimg(csuser['header_url']),
              fit: BoxFit.cover,
            )
          ),
        ),
        BackdropFilter( // 高斯模糊蒙层
          filter: ImageFilter.blur(sigmaX: 20.0,sigmaY: 10.0),
          child: Opacity(
            opacity: 0.6,
            child: Container(
              height: ScreenUtil().setWidth(340),
              decoration: BoxDecoration(
                color:Color.fromRGBO(0, 0, 0, 0.3)
              ),
            ),
          )
        ),
        Container(
          margin: EdgeInsets.all(0),
          padding: EdgeInsets.fromLTRB(
            ScreenUtil().setWidth(29), 
            ScreenUtil().setWidth(74), 
            ScreenUtil().setWidth(29), 
            ScreenUtil().setWidth(34)
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Row(
                children: <Widget>[
                  Container( // 圆角头像
                    width: ScreenUtil().setWidth(130),
                    height: ScreenUtil().setWidth(130),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: getCsHeadimg(csuser['header_url']),
                        fit: BoxFit.cover
                      ),
                      borderRadius: BorderRadius.circular(50)
                    ),
                  ),
                ],
              ),
              Container(
                margin: EdgeInsets.fromLTRB(
                  ScreenUtil().setWidth(0),
                  ScreenUtil().setWidth(30),
                  ScreenUtil().setWidth(0),
                  ScreenUtil().setWidth(0)
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(
                      csuser['nickname'] == '' ? '******' : csuser['nickname'],
                      style: TextStyle(
                        color: Theme.of(context).primaryIconTheme.color,
                        fontSize: ScreenUtil().setWidth(28),
                        fontWeight: FontWeight.w600
                      ),
                    ),
                    SizedBox(
                      height: ScreenUtil().setWidth(10),
                    ),
                    Text(
                      csuser['username'] == '' ? '******' : csuser['username'],
                      style: TextStyle(
                        color: Theme.of(context).primaryIconTheme.color,
                        fontSize: ScreenUtil().setWidth(22),
                      ),
                    )
                  ],
                )
              ),
            ],
          )
        ),
      ],
    );
  }
}